// @ts-ignore
/* eslint-disable */
import request from '@/request'

/** 判断存储桶是否存在 GET /api/minio/bucketExists */
export async function bucketExistsUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.bucketExistsUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>('/api/minio/bucketExists', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 删除图片 POST /api/minio/delete */
export async function removeUsingPost(body: Record<string, any>, options?: { [key: string]: any }) {
  return request<API.BaseResponse>('/api/minio/delete', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  })
}

/** 下载图片 GET /api/minio/download */
export async function downloadUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.downloadUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<any>('/api/minio/download', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 获取所有存储桶 GET /api/minio/getAllBuckets */
export async function getAllBucketsUsingGet(options?: { [key: string]: any }) {
  return request<API.BaseResponse>('/api/minio/getAllBuckets', {
    method: 'GET',
    ...(options || {}),
  })
}

/** 创建存储桶 GET /api/minio/makeBucket */
export async function makeBucketUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.makeBucketUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>('/api/minio/makeBucket', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 预览图片 GET /api/minio/preview */
export async function previewUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.previewUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>('/api/minio/preview', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 删除存储桶 GET /api/minio/removeBucket */
export async function removeBucketUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.removeBucketUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>('/api/minio/removeBucket', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  })
}

/** 上传文件 POST /api/minio/upload */
export async function uploadUsingPost(body: {}, file?: File, options?: { [key: string]: any }) {
  const formData = new FormData()

  if (file) {
    formData.append('file', file)
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele]

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''))
        } else {
          formData.append(ele, JSON.stringify(item))
        }
      } else {
        formData.append(ele, item)
      }
    }
  })

  return request<API.BaseResponse>('/api/minio/upload', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  })
}
